<?php

namespace app\member\controller;

use app\common\controller\Frontend;
use app\admin\model\Member;

class login extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = 'default';

    public function index()
    {
        if(session('memberinfo')){
            $this->error("已登录");

        }
        $url = $this->request->request('url', '');
        $this->view->assign('url', $url);
        $this->view->assign('title', __('Login'));
        return $this->view->fetch();
    }
    public function postdata()
    {
        if(session('memberinfo')){
            $this->error("已登录");

        }
        $account = input('account', '', 'trim');
        $password = input('password', '', 'trim');
        if(empty($account)){
            $this->error('用户名为空');
        }
        if(empty($password)){
            $this->error('密码为空');
        }
        $memberinfo = Member::where(['username'=>$account])->find();
            if(empty($memberinfo)){
            $this->error('账户不存在');
        }
        if($memberinfo['password']!=md5($password)){
            $this->error('密码不正确');
        }
        //登录成功之后把用户信息存储到seesion里面
        session('memberinfo',$memberinfo);
        $this->success("登陆成功",'index/index/index');
    }
    public function logout(){
        session('memberinfo',null);
        $this->success("退出成功",'index/index/index');

    }

    //1,根据账号取出数据，取不出来数据说明没这个用户
    //2,根据取出的数据进行密码匹配，匹配不成功说明密码错误，重新登陆


}
